<template>
  <vxe-modal v-model="modalVisible" ref="xModal" :title="title" width="800" height="365" resize remember>
    <template>
      <vxe-form
          ref="xForm"
          class="data-form"
          title-align="right"
          title-width="60"
          :data="formData"
          :rules="formRules"
          @submit="submitEvent">
        <vxe-form-item title="实施人" field="Completeid" span="24" title-width="65">
          <template v-slot="scope">
            <select-project-team v-model="formData.Completeid"></select-project-team>
          </template>
        </vxe-form-item>
        <vxe-form-item title="检查人" field="Acceptid" span="24" title-width="65">
          <template v-slot="scope">
            <select-project-team v-model="formData.Acceptid"></select-project-team>
          </template>
        </vxe-form-item>
        <vxe-form-item title="描述" field="note" span="24" title-width="65">
          <vxe-textarea v-model="formData.note" :autosize="{minRows: 4}"></vxe-textarea>
        </vxe-form-item>
        <vxe-form-item span="24" align="center">
          <template v-slot>
            <el-button type="primary" native-type="submit">确定</el-button>
            <el-button @click="modalVisible = false">关闭</el-button>
          </template>
        </vxe-form-item>
      </vxe-form>
    </template>
  </vxe-modal>
</template>

<script>
import SelectProjectTeam from "@/components/element/select/SelectProjectTeam";
import projectTaskApi from "@/api/projectTaskApi";
export default {
  components: {
    SelectProjectTeam
  },
  props: {
    formData: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      require: true
    }
  },
  computed: {
    modalVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data () {
    return {
      formRules: {
        Acceptid: [{required: true, message: '请选择检查人', trigger: 'change'}],
        Completeid: [{required: true, message: '请选择实施人', trigger: 'change'}]
      }
    }
  },
  methods: {
    submitEvent () {
      let obj = {
        id: this.formData.Id ,
        acceptid: this.formData.Acceptid,
        note: this.formData.note
      }
      projectTaskApi.accept(obj).then(res => {
        this.$XModal.message({message: res.message, status: res.code === 1 ? 'success' : 'error'})
        this.$emit('search')
        if (res.code === 1) this.modalVisible = false
      })
    }
  }
}
</script>

<style>

</style>
